package com.atguigu.java.ai.langchain4j.config;

import com.atguigu.java.ai.langchain4j.store.MongoChatMemoryStore;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.loader.ClassPathDocumentLoader;
import dev.langchain4j.data.document.splitter.DocumentByParagraphSplitter;
import dev.langchain4j.data.document.splitter.DocumentBySentenceSplitter;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.embedding.EmbeddingModel;

import dev.langchain4j.rag.content.retriever.ContentRetriever;
import dev.langchain4j.rag.content.retriever.EmbeddingStoreContentRetriever;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.IngestionResult;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;
import java.util.List;

/**
 * @Author:Simple
 * @Date: 2025/9/2 15:07
 * @Description:
 **/
@Configuration
public class XiaozhiAgentConfig {
    @Autowired
    private EmbeddingStore embeddingStore;
    @Autowired
    private EmbeddingModel embeddingModel;
    @Autowired
    private MongoChatMemoryStore mongoChatMemoryStore;
    /**
     * @author: Simple
     * @date: 2025-09-05 17:10:17
     * @description: 配置一个chatMemoryProvider
     */
    @Bean
    public ChatMemoryProvider chatMemoryProviderXiaozhi(){
        return memoryId-> MessageWindowChatMemory.builder()
                .maxMessages(10)
                .id(memoryId)
                .chatMemoryStore(mongoChatMemoryStore)
                .build();
    }
    /**
     * @author: Simple
     * @date: 2025-09-04 20:49:56
     * @description: 配置读取pinecone数据库中的 数据
     */
    @Bean
    public ContentRetriever contentRetrieverXiaozhiPincone(){
        return EmbeddingStoreContentRetriever.builder()
                .embeddingStore(embeddingStore)
                .embeddingModel(embeddingModel)
                .minScore(0.8)
                .maxResults(1)
                .build();
    }

    public ContentRetriever contentRetriever(){
        return EmbeddingStoreContentRetriever.builder()
                .maxResults(1)
                .minScore(0.8)
                .embeddingModel(embeddingModel)
                .embeddingStore(embeddingStore)
                .build();
    }
}
